< previous page page_315 next page >

Page 315
    strVersion = InputBox("Enter target version" & vbCrLf & "1.1, 2.0, 2.5,
arrow.gif3.0, 3.5", strHeader)
    MsgBox strVersion
    Select Case Trim(strVersion)
        Case "1.1"
            intVersion = dbVersion11
        Case "2.0"
            intVersion = dbVersion20
        Case "2.5"
            intVersion = dbVersion20
        Case "3.0"
            intVersion = dbVersion30
        Case "3.5"
            intVersion = dbVersion30
        Case Else
            MsgBox "Invalid version!", vbCritical, "Version Error"
            GoTo dbVersion
    End Select
    '
    ' encryption check
    intEncrypt = MsgBox("Encrypt this Database?", vbInformation + vbYesNo, strHeader)
    If intEncrypt = vbYes Then
        intEncrypt = dbEncrypt
    Else
        intEncrypt = dbDecrypt
    End If
    '
    ' now try to do it!
    DBEngine.CompactDatabase strOldDBName, strNewDBName, dbLangGeneral,
intVersion + intEncrypt
    MsgBox "Process Completed"
    '
End Sub
The code in Listing 9.4 declares its local variables and then prompts the user to enter the database file to compact or convert. If no filename is entered, the routine skips to the exit. If a filename is entered, the user is prompted to enter a target filename. If no name is entered, the program returns to try the whole thing again. After getting the filename, the user is prompted to supply the target MSJH version number. The value entered is checked and the user is returned to the input box if an invalid option was entered. Finally, the user is asked whether the database should be encrypted. After that, the CompactDatabase method is invoked.
Save your work and execute this program. You are prompted to enter the name of the database to compact. Enter the path and name for DBREPAIR.MDB. You then must enter a database to compact to. You can just accept the filename suggested to you. Next, enter the version. Answer Yes when you are prompted with the encryption question. The new database is now compacted and saved.

 
< previous page page_315 next page >

If you like this book, buy it!